﻿using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using XYAC.Framework.MonitorTireMaterialManual.DataExporter;
using XYAC.Framework.MonitorTireMaterialManual.OracleRemoteDB;

namespace XYAC.Framework.MonitorTireMaterialManual.DTO
{
    /// <summary>
    /// 胎面报表数据
    /// </summary>
    public partial class SemiSteelTreadScanReport : ObservableObject
    {

        public SemiSteelTreadScanReport()
        {
            LastSyncDate = DateTime.Now;
        }

        [ObservableProperty]
        public int _iD;
        //public string? UserId { get; set; }
        /// <summary>
        /// 补偿系数
        /// </summary>
        [Description("补偿系数")]
        [ObservableProperty]
        public float _compensationCoefficient;

        /// <summary>
        /// 规格号
        /// </summary>
        [Description("规格号")]
        [ObservableProperty]
        public string? _specName;

        /// <summary>
        /// 实际规格号
        /// </summary>
        [Description("实际规格号")]
        [ObservableProperty]
        private string? _specNameInfact;

        [ObservableProperty]
        private string? _serialNumber;
        [ObservableProperty]
        private string? _scanedDatetime;

        /// <summary>
        /// 面积差比
        /// </summary>
        [Description("面积差比")]
        [ObservableProperty]
        public double _totalArea;
        [ObservableProperty]
        public double _totalLeftArea;
        [ObservableProperty]
        public double _totalRightArea;
        [ObservableProperty]
        public double _measureArea;
        [ObservableProperty]
        public double _measureLeftArea;
        [ObservableProperty]
        public double _measureRightArea;
        /// <summary>
        /// 总宽标准
        /// </summary>
        [Description("总宽标准")]
        [ObservableProperty]
        public double _totalWidth_Stable;

        /// <summary>
        /// 总宽扫描
        /// </summary>
        [Description("总宽扫描")]
        [ObservableProperty]
        public double _totalWidth_Scan;

        /// <summary>
        /// 冠宽对称性
        /// </summary>
        [Description("冠宽对称性")]
        [ObservableProperty]
        public double _totalWidth_Symmetry;
        /// <summary>
        /// 冠宽标准
        /// </summary>
        [Description("冠宽标准")]
        [ObservableProperty]
        public double _crownWidth_Stable;

        /// <summary>
        /// 冠宽扫描
        /// </summary>
        [Description("冠宽扫描")]
        [ObservableProperty]
        public double _crownWidth_Scan;

        /// <summary>
        /// 冠宽对称性
        /// </summary>
        [Description("冠宽对称性")]
        [ObservableProperty]
        public double _crownWidth_Symmetry;
        /// <summary>
        /// 肩厚标准
        /// </summary>
        [Description("肩厚标准")]
        [ObservableProperty]
        public double _shoulderThickness_Stable;
        /// <summary>
        /// 肩厚扫描左
        /// </summary>
        [Description("肩厚扫描左")]
        [ObservableProperty]
        public double _shoulderThickness_ScanLeft;
        /// <summary>
        /// 肩厚扫描右
        /// </summary>
        [Description("肩厚扫描右")]
        [ObservableProperty]
        public double _shoulderThickness_ScanRight;
        /// <summary>
        /// 肩厚对称性
        /// </summary>
        [Description("肩厚对称性")]
        [ObservableProperty]
        public double _shoulderThickness_Symmetry;
        /// <summary>
        /// 冠宽标准
        /// </summary>
        [Description("冠宽标准")]
        [ObservableProperty]
        public double _crownThickness_Stable;

        /// <summary>
        /// 冠宽扫描
        /// </summary>
        [Description("冠宽扫描")]
        [ObservableProperty]
        public double _crownThickness_Scan;

        /// <summary>
        /// 其他点厚度标准
        /// </summary>
        [Description("其他点厚度标准")]
        [ObservableProperty]
        public string? _othoerPointsThickness_Stable;
        /// <summary>
        /// 其他点厚度扫描
        /// </summary>
        [Description("其他点厚度扫描")]
        [ObservableProperty]
        public string? _othoerPointsThickness_Scan;
        /// <summary>
        /// 胎翼端点厚度扫描左
        /// </summary>
        [Description("胎翼端点厚度扫描左")]
        [ObservableProperty]
        public double _beadWingTipThickness_ScanLeft;
        /// <summary>
        /// 胎翼端点厚度扫描右
        /// </summary>
        [Description("胎翼端点厚度扫描右")]
        [ObservableProperty]
        public double _beadWingTipThickness_ScanRight;
        /// <summary>
        /// 胎翼宽度标准
        /// </summary>
        [Description("胎翼宽度标准")]
        [ObservableProperty]
        public double _beadWingWidth_Stable;
        /// <summary>
        /// 胎翼宽度扫描左
        /// </summary>
        [Description("胎翼宽度扫描左")]
        [ObservableProperty]
        public double _beadWingWidth_ScanLeft;
        /// <summary>
        /// 胎翼宽度扫描右
        /// </summary>
        [Description("胎翼宽度扫描右")]
        [ObservableProperty]
        public double _beadWingWidth_ScanRight;
        /// <summary>
        /// 胎翼宽度对称性
        /// </summary>
        [Description("胎翼宽度对称性")]
        [ObservableProperty]
        public double _beadWingWidth_Symmetry;
        /// <summary>
        /// 天线胶形状、尺寸
        /// 上宽（mm）2.0±1.0
        /// </summary>
        [Description("天线胶形状、尺寸(上宽（mm）2.0±1.0)")]
        [ObservableProperty]
        public double _antennaAdhesiveSpec_TopWidth;
        /// <summary>
        /// 天线胶形状、尺寸
        /// 下宽（mm）2.0±1.0
        /// </summary>
        [Description("天线胶形状、尺寸(下宽（mm）2.0±1.0)")]
        [ObservableProperty]
        public double _antennaAdhesiveSpec_BottomWidth;
        /// <summary>
        /// 天线胶形状、尺寸
        /// 贯通（mm）2.0±1.0
        /// </summary>
        [Description("天线胶形状、尺寸(贯通（mm）2.0±1.0)")]
        [ObservableProperty]
        public string? _antennaAdhesiveSpec_Penetration;

        /// <summary>
        /// 同步状态
        /// </summary> 
        [ObservableProperty]
        public bool _syncState;
        /// <summary>
        /// 最后同步时间
        /// </summary> 
        [ObservableProperty]
        public DateTime? _lastSyncDate = DateTime.Now;
        /// <summary>
        /// 机台编码
        /// </summary>
        [Description("机台编码")]
        [ObservableProperty]
        public string? _eqp;
        /// <summary>
        /// 断面形状
        /// </summary>
        [Description("断面形状")]
        [ObservableProperty]
        public string? _crossSectionShape;


        [ObservableProperty]
        private string? _userId;

        [ObservableProperty]
        private string? _shift;
        /// <summary>
        /// 总面积%
        /// 
        /// </summary>
        [ObservableProperty]
        private float _data8;

        /// <summary>
        /// 总宽(mm)  左 标准
        /// </summary>
        [ObservableProperty]
        private float _data9;
        /// <summary>
        /// 总宽(mm)  左 实测
        /// </summary>
        [ObservableProperty]
        private float _data13;

        /// <summary>
        /// 总宽(mm)  右 标准
        /// </summary>
        [ObservableProperty]
        private float _data10;
        /// <summary>
        /// 总宽(mm)  右 实测
        /// </summary>
        [ObservableProperty]
        private float _data14;

        /// <summary>
        /// 总宽(mm)    标准
        /// SemiSteelTreadScanReport.TotalWidth_Stable
        /// </summary>
        [ObservableProperty]
        private float _data11;
        /// <summary>
        /// 总宽(mm)    实测
        /// </summary>
        [ObservableProperty]
        private float _data15;
        /// <summary>
        /// 左右宽度差
        /// </summary>
        [ObservableProperty]
        private float _data18;

        /// <summary>
        /// 肩厚（mm）  左 标准
        /// </summary>
        [ObservableProperty]
        private float _data19;
        /// <summary>
        /// 肩厚（mm）  左 实测
        /// </summary>
        [ObservableProperty]
        private float _data22;

        /// <summary>
        /// 肩厚（mm）  右 标准
        /// </summary>
        [ObservableProperty]
        private float _data20;
        /// <summary>
        /// 肩厚（mm）  右 实测
        /// </summary>
        [ObservableProperty]
        private float _data23;

        /// <summary>
        /// 左右肩厚差
        /// </summary>
        [ObservableProperty]
        private float _data24;

        //冠宽(mm)
        /// <summary>
        /// 冠宽(mm)  左 标准
        /// </summary>
        [ObservableProperty]
        private float _data25;
        /// <summary>
        /// 冠宽(mm)  左 实测
        /// </summary>
        [ObservableProperty]
        private float _data29;
        /// <summary>
        /// 冠宽(mm)  右 标准
        /// </summary>
        [ObservableProperty]
        private float _data26;
        /// <summary>
        /// 冠宽(mm)  右 实测
        /// </summary>
        [ObservableProperty]
        private float _data30;

        /// <summary>
        /// 冠宽(mm)    标准
        /// </summary>
        [ObservableProperty]
        private float _data27;
        /// <summary>
        /// 冠宽(mm)     实测
        /// </summary>
        [ObservableProperty]
        private float _data31;

        /// <summary>
        /// 左右冠宽差    实测
        /// </summary>
        [ObservableProperty]
        private float _data32;

        //冠厚(mm)
        /// <summary>
        /// 冠厚(mm)    标准
        /// </summary>
        [ObservableProperty]
        private float _data33;
        /// <summary>
        /// 冠厚    实测
        /// </summary>
        [ObservableProperty]
        private float _data34;

        /// <summary>
        /// 断面形状    实测
        /// </summary>
        [ObservableProperty]
        private string? _checkPoint36 = "True";

        /// <summary>
        /// 胎翼宽度(mm)  左  实测
        /// </summary>
        [ObservableProperty]
        private float _data40;
        /// <summary>
        /// 胎翼宽度(mm)  右  实测
        /// </summary>
        [ObservableProperty]
        private float _data41;
        /// <summary>
        /// 胎翼宽度(mm)  左右宽度差  实测
        /// </summary>
        [ObservableProperty]
        private float _data42;


        /// <summary>
        /// 边缘端点厚度(mm)  左  实测
        /// </summary>
        [ObservableProperty]
        private float _data45;
        /// <summary>
        /// 边缘端点厚度(mm)  右  实测
        /// </summary>
        [ObservableProperty]
        private float _data46;

        /// <summary>
        /// 天线胶形状、尺寸  天线胶上端宽度(mm)  实测
        /// </summary>
        [ObservableProperty]
        private float _data50;
        /// <summary>
        /// 天线胶形状、尺寸  天线胶下端宽度(mm)  实测
        /// </summary>
        [ObservableProperty]
        private float _data51;

        /// <summary>
        /// 天线胶形状、尺寸 天线胶贯通  实测
        /// </summary>
        [ObservableProperty]
        private string? _checkPoint52 = "NULL";

        /// <summary>
        /// 其它点厚度(mm) 标准
        /// </summary>
        [ObservableProperty]
        private string? _checkPoint53 = "True";
        /// <summary>
        /// 其它点厚度(mm) 实测
        /// </summary>
        [ObservableProperty]
        private string? _checkPoint54 = "True";

        /// <summary>
        /// 判定
        /// </summary>
        [ObservableProperty]
        private string? _passStatus = "True";

        /// <summary>
        /// MAX基部胶厚度  标准
        /// </summary>
        [ObservableProperty]
        private float _manuData30D;
        /// <summary>
        /// MAX基部胶厚度  公差
        /// </summary>
        [ObservableProperty]
        private float _manuData30E;
        /// <summary>
        /// MAX基部胶厚度  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData30F;

        /// <summary>
        /// MIN基部胶厚度  标准
        /// </summary>
        [ObservableProperty]
        private float _manuData31D;
        /// <summary>
        /// MIN基部胶厚度  公差
        /// </summary>
        [ObservableProperty]
        private float _manuData31E;
        /// <summary>
        /// MIN基部胶厚度  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData31F;

        /// <summary>
        /// 基部胶厚度差  标准
        /// </summary>
        [ObservableProperty]
        private float _manuData32D;
        /// <summary>
        /// 基部胶厚度差  公差
        /// </summary>
        [ObservableProperty]
        private float _manuData32E;
        /// <summary>
        /// 基部胶厚度差  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData32F;

        /// <summary>
        /// 胎面基部胶最小厚度  标准
        /// </summary>
        [ObservableProperty]
        private float _manuData33D;
        /// <summary>
        /// 胎面基部胶最小厚度  公差
        /// </summary>
        [ObservableProperty]
        private float _manuData33E;
        /// <summary>
        /// 胎面基部胶最小厚度  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData33F;

        /// <summary>
        /// TUC差级ⅠA-BⅠ(mm)  实测
        /// </summary>
        [ObservableProperty]
        private float _manuData34F;

        /// <summary>
        /// 备注
        /// </summary>
        [ObservableProperty]
        private string? _remark;
        [ObservableProperty]
        private float? _areaPercent;
        
        public YB_PROCESS_STEP ToYB_PROCESS_STEP(DataFile dataFile)
        {
            //var dataFile = DataFile.FromSpecVal(this.SpecVal);
            var processStep = new YB_PROCESS_STEP
            {
                // 映射 SemiSteelTreadScanReport 的字段到 RECORD16 至 RECORD43 
                //PLAN_ID = this.PlanId,
                PART_NUMBER = this.SpecName,
                RECORD122 = this.Data8.ToString("F1"),// this.TotalArea.ToString("F1"),
                RECORD123 = this.MeasureArea.ToString("F1"),
                RECORD124 = this.TotalLeftArea.ToString("F1"),
                RECORD125 = this.MeasureLeftArea.ToString("F1"),
                RECORD126 = this.TotalRightArea.ToString("F1"),
                RECORD127 = this.MeasureRightArea.ToString("F1"),
                //总宽设定值
                RECORD128 = this.TotalWidth_Stable.ToString("F1"),
                RECORD129 = this.TotalWidth_Scan.ToString("F1"),
                //左侧宽设定值
                RECORD130 = (this.TotalWidth_Stable / 2).ToString("F1"),
                RECORD131 = Math.Abs(dataFile.XReference - dataFile.MeasureKeys.FirstOrDefault().Coordinate).ToString("F1"),
                //右侧宽设定值
                RECORD132 = (this.TotalWidth_Stable / 2).ToString("F1"),
                RECORD133 = Math.Abs(dataFile.XReference - dataFile.MeasureKeys.LastOrDefault().Coordinate).ToString("F1"),
                //冠宽设定值
                RECORD134 = this.CrownWidth_Stable.ToString("F1"),
                RECORD135 = this.CrownWidth_Scan.ToString("F1"),
                //左冠宽设定值
                RECORD136 = Math.Abs((dataFile.StableKeys.ElementAt(dataFile.StableKeys.Count() - 2).Coordinate - dataFile.StableKeys[1].Coordinate) / 2).ToString("F1"),
                RECORD137 = Math.Abs(dataFile.XReference - dataFile.MeasureKeys[1].Coordinate).ToString("F1"),
                //右冠宽设定值
                RECORD138 = Math.Abs((dataFile.StableKeys.ElementAt(dataFile.StableKeys.Count() - 2).Coordinate - dataFile.StableKeys[1].Coordinate) / 2).ToString("F1"),
                RECORD139 = Math.Abs(dataFile.MeasureKeys.ElementAt(dataFile.MeasureKeys.Count() - 2).Coordinate - dataFile.XReference).ToString("F1"),
                //左肩厚设定值
                RECORD140 = dataFile.StableKeys[1].Value.ToString("F1"),
                RECORD141 = dataFile.MeasureKeys[1].Value.ToString("F1"),
                //右肩厚设定值
                RECORD142 = dataFile.StableKeys.ElementAt(dataFile.StableKeys.Count() - 2).Value.ToString("F1"),
                RECORD143 = dataFile.MeasureKeys.ElementAt(dataFile.MeasureKeys.Count() - 2).Value.ToString("F1"),
                //冠厚设定值
                RECORD144 = this.CrownThickness_Stable.ToString("F1"),
                RECORD145 = (this.CrownThickness_Scan + this.CompensationCoefficient).ToString("F1"),//+补偿值
                //左胎翼端点厚度设定值
                RECORD146 = dataFile.StableKeys[0].Value.ToString("F1"),
                RECORD147 = dataFile.MeasureKeys[0].Value.ToString("F1"),
                //右胎翼端点厚度设定值
                RECORD148 = dataFile.StableKeys.LastOrDefault().Value.ToString("F1"),
                RECORD149 = dataFile.MeasureKeys.LastOrDefault().Value.ToString("F1"),
                //左胎翼宽度设定值
                RECORD150 = Math.Abs(dataFile.StableKeys[1].Coordinate - dataFile.StableKeys[0].Coordinate).ToString("F1"),
                RECORD151 = Math.Abs(dataFile.MeasureKeys[1].Coordinate - dataFile.MeasureKeys[0].Coordinate).ToString("F1"),
                //右胎翼宽度设定值
                RECORD152 = Math.Abs(dataFile.StableKeys.ElementAt(dataFile.StableKeys.Count() - 2).Coordinate - dataFile.StableKeys.LastOrDefault().Coordinate).ToString("F1"),
                RECORD153 = Math.Abs(dataFile.MeasureKeys.ElementAt(dataFile.MeasureKeys.Count() - 2).Coordinate - dataFile.MeasureKeys.LastOrDefault().Coordinate).ToString("F1"),
                //检测结果
                //RECORD154 = this.SpecVal.TestResult,
                //问题点RECORD155
                //RECORD156 = dataFile.FileInertvaWidth.ToString("F1"),

                //检验员
                RECORD159 = this.UserId,
                //面积比
                RECORD160 = this.AreaPercent?.ToString("F1"),
                //总宽对称性
                RECORD161 = this.TotalWidth_Symmetry.ToString("F1"),
                //冠宽对称性
                RECORD162 = this.CrownWidth_Symmetry.ToString("F1"),
                //断面形状
                RECORD164 = this.CheckPoint36, //this.CrossSectionShape,
                //RECORD163
                RECORD163 = this.ShoulderThickness_Symmetry.ToString("F1"),
                //胎翼宽度对称性
                RECORD165 = this.BeadWingWidth_Symmetry.ToString("F1"),
                //天线胶上宽
                RECORD166 = this.Data50.ToString("F1"), //this.AntennaAdhesiveSpec_TopWidth.ToString("F1"),
                //天线胶下宽
                RECORD167 = this.Data51.ToString("F1"),//this.AntennaAdhesiveSpec_BottomWidth.ToString("F1"),
                //天线胶贯通
                RECORD168 = this.CheckPoint52, //this.AntennaAdhesiveSpec_Penetration,
                //其他点厚度标准
                //RECORD177 = this.OthoerPointsThickness_Stable,
                //其他点厚度扫描
                //RECORD178 = this.OthoerPointsThickness_Scan,

                EQP = this.Eqp,

                RECORD154 = this.ManuData30D.ToString("F1"),  //MAX基部胶厚度标准
                RECORD155 = this.ManuData30E.ToString("F1"),  //  MAX基部胶厚度公差
                RECORD156 = this.ManuData31D.ToString("F1"),  //   MIN基部胶厚度标准
                RECORD157 = this.ManuData31E.ToString("F1"),  //   MIN基部胶厚度公差

                RECORD158 = this.ManuData34F.ToString("F1"),  //  TUC差级实际值

                RECORD177 = this.CheckPoint53,//  其他点厚度标准
                RECORD178 = this.CheckPoint54,//  其他点厚度扫描

                RECORD169 = this.Shift,//  班次
                RECORD170 = this.ManuData30F.ToString("F1"),  //   MAX基部胶厚度实际
                RECORD171 = this.ManuData31F.ToString("F1"),  //   MIN基部胶厚度实际
                RECORD172 = this.ManuData32D.ToString("F1"),  //   基部胶厚度差标准
                RECORD173 = this.ManuData32E.ToString("F1"),  //   基部胶厚度差公差
                RECORD174 = this.ManuData32F.ToString("F1"),  //   基部胶厚度差实际

                RECORD179 = this.ManuData33D.ToString("F1"),  //  胎面基部胶最小厚度标准
                RECORD180 = this.ManuData33E.ToString("F1"),  //  胎面基部胶最小厚度公差
                RECORD181 = this.ManuData33F.ToString("F1"),  //  胎面基部胶最小厚度实际

                RECORD225 = this.PassStatus,    //  判定结果
                RECORD226 = this.Remark,        //  备注
                RECORD227 = this.SpecNameInfact,//  实际规格

            };
            //this.UpdateProcessStep(processStep, dataFile);
            return processStep;
        }
    }
}
